/**
 * 
 */
package de.peacei.android.ioex_notesapp;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

/**
 * @author Matthias
 *
 */
public class NoteListAdapter extends BaseAdapter {
    
    private final LayoutInflater inflater;
    
    public NoteListAdapter(Context context) {
        inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    private List<Note> notesList = new ArrayList<Note>();
    
    
    public void setNotes(List<Note> notes) {
        this.notesList = notes;
        this.notifyDataSetChanged();
    }
    
    @Override
    public int getCount() {
        return notesList.size();
    }

    /* (non-Javadoc)
     * @see android.widget.Adapter#getItem(int)
     */
    @Override
    public Note getItem(int position) {
        return notesList.get(position);
    }


    @Override
    public long getItemId(int position) {
        return Long.valueOf(notesList.get(position).hashCode());
    }


    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        
        TextView view = (TextView) inflater.inflate(R.layout.list_item, null);
        view.setText(notesList.get(position).toString());
        return view;
    }

}
